package com.nmwlw.demo.ui

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.nmwlw.demo.data.viewModle.WifiSetModel

@Preview(device = Devices.AUTOMOTIVE_1024p,
    widthDp = 2173,
    heightDp = 	1223,
    showBackground = true)
@Composable
fun WifiSetPreview() {
    WifiSetScreen()
}

@Composable
fun WifiSetScreen(wifiSetModel: WifiSetModel = viewModel()) {
    val wifiSetState by wifiSetModel.wifiSetState.collectAsState()
    Row (
        modifier = Modifier
            .fillMaxWidth()

    ){
        Column(
            modifier = Modifier
                .fillMaxHeight()
                .weight(1f)

        ) {
            Row(
                verticalAlignment = Alignment.CenterVertically
            ) {
                Text(
                    text = "打开wifi",
                    fontSize = 28.sp
                )
                Spacer(modifier = Modifier.weight(1f))
                Switch(
                    checked = wifiSetState.wifiEnable,
                    onCheckedChange = {
                        wifiSetModel.enableWifi()
                    }
                )
            }


        }

        Column(
            modifier = Modifier
                .fillMaxHeight()
                .weight(1f)
        ) {

        }
    }
}
